﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ApprovalStepEdit.ascx.cs" Inherits="CentralOffice.WebClient.Admin.Flow.ApprovalStepEdit" %>

<table class="TableBlock" width="90%" align="center">
<tr>
    <td class="TableData" width=15%>审批对象：</td><td class="TableData"><asp:DropDownList ID="ddlApprovalObject" runat="server" AutoPostBack="true"  onselectedindexchanged="ddlApprovalObject_SelectedIndexChanged"></asp:DropDownList></td>
    <td class="TableData" width=15%>审批流程：</td><td class="TableData">
        <asp:UpdatePanel UpdateMode="Conditional" ID="upApprovalProcess" runat="server" ChildrenAsTriggers="false">
            <ContentTemplate>
                <asp:DropDownList ID="ddlApprovalProcess" runat="server" OnSelectedIndexChanged="ddlApprovalProcess_SelectedIndexChanged"  AutoPostBack="true"></asp:DropDownList>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="ddlApprovalObject" />
            </Triggers>
        </asp:UpdatePanel>
    </td>
</tr>
<tr>
    <td class="TableData">步骤名称：</td><td class="TableData"><asp:TextBox ID="txtName" runat="server" CssClass="BigInput" ></asp:TextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="必须填写步骤名称" ControlToValidate="txtName">*</asp:RequiredFieldValidator><span class="warning">(必填)</span></td>
    <td class="TableData">审批者：</td><td class="TableData">
    
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" RenderMode="Inline">
            <ContentTemplate>
                <input type="text" id="txtEmpReadOnly" style="width: 60%" name="txtExecutorReadOnly" class="SmallStatic" runat="server" readonly="readonly" />
                <asp:HiddenField ID="txtEmp" runat="server" />&nbsp;
                <asp:LinkButton ID="btnShowPopup" CommandName="ApprovedBy" runat="server" OnClick="btnShowPopup_Click" CssClass="orgAdd">选择</asp:LinkButton>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="btnEmpOK" />
            </Triggers>
        </asp:UpdatePanel>&nbsp;
        <a href="javascript:;" class="orgClear" onclick="$get('<%= txtEmpReadOnly.ClientID %>').value='';$get('<%= txtEmp.ClientID %>').value='';">清空</a>
    
    </td>
</tr>
<tr>
    <td class="TableData">步骤序号：</td><td class="TableData"><asp:TextBox ID="txtStepOrder" runat="server" CssClass="BigInput"></asp:TextBox><asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="步骤序号为0到255" ControlToValidate="txtStepOrder" MaximumValue="255" MinimumValue="0" Type="Integer" Display="Dynamic"></asp:RangeValidator><span class="warning">(0-255)</span></td>   
    <td class="TableData">审批角色：</td><td class="TableData"><asp:TextBox ID="txtRoles" runat="server" CssClass="BigStatic" ></asp:TextBox>&nbsp;&nbsp;<asp:LinkButton ID="btnAddRole" runat="server" CssClass="orgAdd">添加</asp:LinkButton><a href="javascript:;" class="orgClear" onclick="roleBox.value='';">清空</a></td>   
</tr>

<tr>
    <td class="TableData">审批内容：</td><td class="TableData" colspan="3"><asp:TextBox ID="txtContent" runat="server" CssClass="BigInput"  style="width:80%;"></asp:TextBox></td>
</tr>
 
<tr align="center" class="TableControl">
    <td colspan="4">
        <asp:Button ID="btnQuery" runat="server" Text="保存" CssClass="BigButton" OnClientClick="if(document.getElementById('ApprovalStepEdit1_txtEmp').value.length == 0 && document.getElementById('ApprovalStepEdit1_txtRoles').value.length == 0) { alert('您必须选定一个审批者！');  return false;} if(document.getElementById('ApprovalStepEdit1_txtEmp').value.indexOf(',') > 0) { alert('您只能选择一个审批者！');  return false;}"
            OnClick="btnQuery_Click" />
        <asp:Button ID="btnContinue" runat="server" Text="保存并继续添加" CssClass="BigButton" 
            style="margin-left:65px;" onclick="btnContinue_Click"  />
        <input type="button" value="取消" class="BigButton" style="margin-left:65px;" onclick="window.parent.location='default.htm';" />
    </td>
</tr>
</table>
<asp:Literal ID="lblJavaScript" EnableViewState="false" runat="server"></asp:Literal>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableViewState="false" />

<asp:Panel ID="PopupPanel" runat="server" CssClass="x-pne" style="display:none; width:460px;">
  <%--  
    <div>
        <p style="margin:2px;" >
        
        </p>
        <p style="text-align: center;">
        
            <input id="btnReserve" type="button" value="反选" style="text-align:left;" onclick="reserve();" />&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Button ID="OkButton" runat="server" Text="确定" />&nbsp;&nbsp;
            <asp:Button ID="CancelButton" runat="server" Text="取消" />
            
        </p>
    </div>
    --%>
    <asp:Panel ID="DragPanel" runat="server" CssClass="corner-bg x-pne-lt x-pne-left">
        <div class="corner-bg x-pne-rt x-pne-right">
            <div class="corner-bg x-pne-t dragTitle">
                <div class="x-pne-btn" id="Div1" onclick="$find('rolesBehavior').hide();"></div>
                <div class="x-pne-caption font dragTitle"><span>请选择角色：</span></div>
            </div>
        </div>
    </asp:Panel>

    <div>
    
        <div class="side-bg x-pne-l">
            <div class="side-bg x-pne-r">
                <div class="x-pne-c" style="WIDTH: 448px;">
					<div style="margin:10px;font-size:9pt;" class="wrapper">
					
<div id="div2" style="width:430px;height:300px; overflow:auto;">
    <asp:CheckBoxList ID="cbListRole" runat="server" RepeatColumns="3" DataSourceID="odsRoles" DataTextField="RoleName" DataValueField="RoleId" Font-Size="9pt"></asp:CheckBoxList>
    <asp:ObjectDataSource ID="odsRoles" TypeName="Husb.Security.RoleManager" SelectMethod="GetAllRoleList" runat="server" EnableCaching="True" CacheDuration="1" ></asp:ObjectDataSource>
</div>
                    
                    <!-- 下面是确认按钮 -->
                    <div style="width:328px; margin-top:16px;">
                        <table  style="width:100%; margin-left:40px;">
                            <tr>
                               <td>
<div class="btn-side btn-bg"></div>
<div class="btn-body btn-bg" style="background-position: 0px 168px; width: 66px"><input id="btnReserve" type="button" value="反选" style="text-align:left;" onclick="reserve();" /></div>
<div class="btn-side btn-bg" style="background-position: 0px 189px"></div>
                                </td>
                            
                                <td>
<div class="btn-side btn-bg"></div>
<div class="btn-body btn-bg" style="background-position: 0px 168px; width: 66px"><asp:Button ID="btnOK" runat="server" Text="  确定  " CssClass="font" /></div>
<div class="btn-side btn-bg" style="background-position: 0px 189px"></div>

                                </td>
                                <td>
<div class="btn-side btn-bg"></div>
<div class="btn-body btn-bg" style="background-position: 0px 168px; width: 66px;"><asp:Button ID="btnClose" runat="server" Text="  取消  " CssClass="font" /></div>
<div class="btn-side btn-bg" style="background-position: 0px 189px"></div>
                                </td>
                            </tr>
                        </table>
                    </div>
                        
					</div>
                </div>
            </div>
        </div>

        <div class="corner-bg x-pne-lb x-pne-left">
            <div class="corner-bg x-pne-rb x-pne-right">
                <div class="corner-bg x-pne-b"></div>
            </div>
        </div>
        
    </div>
    
    
</asp:Panel>
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender" runat="server" 
    BehaviorID="rolesBehavior" 
    TargetControlID="btnAddRole"
    PopupControlID="PopupPanel" 
    OkControlID="btnOK"
    OnOkScript="getSelected()" 
    OnAfterShowScript="onAfterShow()"
    CancelControlID="btnClose" 
    DropShadow="false"
    PopupDragHandleControlID="DragPanel" />

<script type="text/javascript">
    //<![CDATA[
//BackgroundCssClass="modalBackground" 
var checkboxList = new Array();
var roleBox = $get('<%= txtRoles.ClientID %>');
var table = $get('<%= cbListRole.ClientID %>');
function getSelected()
{
    var roles = "";

    var checkBoxes = table.getElementsByTagName('INPUT');
    for(var i = 0; i < checkBoxes.length; i++)
    {
        if(checkBoxes[i].type == "checkbox" && checkBoxes[i].checked)
        {
            roles += checkBoxes[i].nextSibling.innerText + ",";
        }
    }

    if(roles.length > 0 && roles.charAt(roles.length - 1) === ",") roles = roles.substr(0, roles.length - 1);
    roleBox.value = roles;
}

function onAfterShow()
{
    var roles = roleBox.value;
    if(roles.length == 0) return;
    var roleList = roles.split(",");
    
    var checkBoxes = table.getElementsByTagName('INPUT');
    for(var i = 0; i < checkBoxes.length; i++)
    {
        if(checkBoxes[i].type == "checkbox" && Array.contains(roleList, checkBoxes[i].nextSibling.innerText))
        {
            checkBoxes[i].checked = true;
        }
        else
        {
            checkBoxes[i].checked = false;
        }
    }
}

function reserve()
{
    var checkBoxes = table.getElementsByTagName('INPUT');
    
    for(var i = 0; i < checkBoxes.length; i++)
    {
        if(checkBoxes[i].type == "checkbox")
        {
            checkBoxes[i].checked = !checkBoxes[i].checked;
        }
    }
}

//]]>
</script>

<asp:Panel ID="pnlPopup" runat="server" CssClass="x-pne" Style="display: none; width: 460px;">
    <asp:UpdatePanel ID="updPnlDepartment" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:Button ID="btnShowEdit" runat="server" Style="display: none" />
            <ajaxToolkit:ModalPopupExtender ID="mdlDetailView" runat="server" BehaviorID="detailView"
                TargetControlID="btnShowEdit" PopupControlID="pnlPopup" CancelControlID="btnEmpCancel"
                BackgroundCssClass="modalBackground" PopupDragHandleControlID="pnlDrag" />
            <asp:Panel ID="pnlDrag" runat="server" CssClass="corner-bg x-pne-lt x-pne-left">
                <div class="corner-bg x-pne-rt x-pne-right">
                    <div class="corner-bg x-pne-t dragTitle">
                        <div class="x-pne-btn" id="Div3" onclick="$find('detailView').hide();">
                        </div>
                        <div class="x-pne-caption font dragTitle">
                            <span>请选择审批者</span></div>
                    </div>
                </div>
            </asp:Panel>
            <div>
                <div class="side-bg x-pne-l">
                    <div class="side-bg x-pne-r">
                        <div class="x-pne-c" style="width: 448px;">
                            <div style="margin: 10px; font-size: 9pt;" class="wrapper">
                                <div id="div4" style="width: 430px; height: 300px; overflow: auto;">
                                    <asp:TreeView ID="tvEmp" runat="server" EnableViewState="true" OnLoad="tvEmp_Load">
                                    </asp:TreeView>
                                </div>
                                <!-- 下面是确认按钮 -->
                                <div style="width: 328px; margin-top: 16px;">
                                    <table style="width: 100%; margin-left: 40px;">
                                        <tr>
                                            <td>
                                                <div class="btn-side btn-bg">
                                                </div>
                                                <div class="btn-body btn-bg" style="background-position: 0px 168px; width: 66px">
                                                    <asp:Button ID="btnEmpOK" runat="server" Text="  确定  " CssClass="font" OnClick="btnOK_Click" /></div>
                                                <div class="btn-side btn-bg" style="background-position: 0px 189px">
                                                </div>
                                            </td>
                                            <td>
                                                <div class="btn-side btn-bg">
                                                </div>
                                                <div class="btn-body btn-bg" style="background-position: 0px 168px; width: 66px;">
                                                    <asp:Button ID="btnEmpCancel" runat="server" Text="  取消  " CssClass="font" /></div>
                                                <div class="btn-side btn-bg" style="background-position: 0px 189px">
                                                </div>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="corner-bg x-pne-lb x-pne-left">
                    <div class="corner-bg x-pne-rb x-pne-right">
                        <div class="corner-bg x-pne-b">
                        </div>
                    </div>
                </div>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Panel>
<asp:UpdateProgress ID="updateProgress" runat="server">
    <ProgressTemplate>
        <div id="progressBackgroundFilter">
        </div>
        <div id="processMessage">
            正在处理数据，请稍等...<br />
            <br />
            <img alt="Loading" src="../images/loading_16.gif" /></div>
    </ProgressTemplate>
</asp:UpdateProgress>
<%--

<asp:UpdatePanel UpdateMode="Conditional" ID="upApprovalProcess" runat="server" ChildrenAsTriggers="false">
    <ContentTemplate>
        <asp:DropDownList ID="ddlApprovalProcess" runat="server" OnSelectedIndexChanged="ddlApprovalProcess_SelectedIndexChanged"
            AutoPostBack="true">
        </asp:DropDownList>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="ddlApprovalObject" />
    </Triggers>
</asp:UpdatePanel>

<asp:UpdatePanel UpdateMode="Conditional" ID="upPreviousStep" runat="server" ChildrenAsTriggers="false">
<ContentTemplate>
    <asp:DropDownList ID="ddlPreviousStep" runat="server"></asp:DropDownList>
</ContentTemplate>
<Triggers>
    <asp:AsyncPostBackTrigger ControlID="ddlApprovalProcess" />
</Triggers>
</asp:UpdatePanel>

--%>

<script type="text/javascript">
    function selectAll() {
        var tree = document.getElementById("<%=tvEmp.ClientID%>");
        if (typeof (tree) === "undefined" && tree === null) return;

        var checkBoxs = tree.getElementsByTagName('INPUT');
        for (var i = 0; i < checkBoxs.length; i++) {
            if (checkBoxs[i].type == "checkbox") {
                checkBoxs[i].checked = true;
            }
        }
    }

    function reverse() {
        var tree = document.getElementById("<%=tvEmp.ClientID%>");
        if (typeof (tree) === "undefined" && tree === null) return;

        var checkBoxs = tree.getElementsByTagName('INPUT');
        for (var i = 0; i < checkBoxs.length; i++) {
            if (checkBoxs[i].type == "checkbox") {
                checkBoxs[i].checked = !checkBoxs[i].checked;
            }
        }
    }

    function OnTreeNodeChecked() {
        var ele = window.event.srcElement;
        if (ele.type == 'checkbox') {
            var childrenDivID = ele.id.replace('CheckBox', 'Nodes');
            var div = document.getElementById(childrenDivID);
            if (div == null) return;
            var checkBoxs = div.getElementsByTagName('INPUT');
            for (var i = 0; i < checkBoxs.length; i++) {
                if (checkBoxs[i].type == 'checkbox')
                    checkBoxs[i].checked = ele.checked;
            }
        }
    }

    function validateClient() {
        if (document.getElementById("txtExecutor").value.length == 0) {
            alert("必须选定执行者！");
            return false;
        }
        return true;
    }
</script>

